import os
import google_play_scraper as google_play_scraper
import json


# 根据包名、语言、国家简称获取应用信息
def get_app_info(app_package_name, lang='en', country='us'):
    result = google_play_scraper.app(
        app_package_name,
        lang=lang,
        country=country,
    )
    return result

# 输出结果见example.json，格式化清洗其中重要字段


if __name__ == '__main__':
    #测试用例
    result = get_app_info('com.gytz.mabilis', 'en', 'ph')
    print( result )
    # 将result结果保存在当前绝对目录下example.json中
    file_path_name1 = './example.json'
    current_path = os.path.dirname(__file__)
    file_path_name1 = file_path_name1.replace("./", current_path + "/")
    with open(file_path_name1, 'w', encoding='utf-8') as f:
        json.dump(result, f, ensure_ascii=False, indent=4)
    